package com.dunshan.deeptest.pojo;

import java.io.Serializable;

/**
 * 公共响应信息
 * @author
 * @param <T>
 */
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private final static String SUCCESS_CODE = "0";
    private final static String DEFAULT_SUCCESS_MSG = "SUCCESS";
    private final static String DEFAULT_FAILED_CODE = "-1";
    private final static String DEFAULT_FAILED_MSG = "ERROR";

    /**
     * 请求结果 (true:成功 false:失败)
     */
    private boolean success;

    /**
     * 响应码
     */
    private String code;

    /**
     * 响应提示信息
     */
    private String message;

    /**
     * 响应数据
     */
    private T data;

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> Result<T> buildSuccess(T data){
        Result result = new Result();
        result.setSuccess(true);
        result.setCode(SUCCESS_CODE);
        result.setMessage(DEFAULT_SUCCESS_MSG);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> buildFailed(String code,String message){
        Result result = new Result();
        result.setSuccess(false);
        result.setCode(code);
        result.setMessage(message);
        result.setData(null);
        return result;
    }

    public static <T> Result<T> buildFailed(){
        return buildFailed(DEFAULT_FAILED_CODE,DEFAULT_FAILED_MSG);
    }

}
